package cassys.actions.classGroupManagement;

import cassys.actions.core.BaseAction;
import cassys.ejb.clients.ModuleManagementDelegate;
import cassys.domain.classManagement.*;
import cassys.ejb.clients.ClassGroupManagementDelegate;
import cassys.ejb.clients.StudentManagementDelegate;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author User
 */
public class ViewClassGroup extends BaseAction {

    private long classGroupId;
    private String title;
    private Module module;
    private List<Module> modules;
    private List<Student> selectedStudents;
    private List<Student> students;
    private ClassGroupManagementDelegate classGroupDelegate;
    private ModuleManagementDelegate moduleDelegate;
    private StudentManagementDelegate studentDelegate;

    public ViewClassGroup() {
        classGroupDelegate = new ClassGroupManagementDelegate();
        moduleDelegate = new ModuleManagementDelegate();
        studentDelegate = new StudentManagementDelegate();
        this.modules = moduleDelegate.getAllModules();
        this.students = studentDelegate.getAllStudents();
    }

    @Override
    public String execute() throws Exception {
        selectedStudents = new ArrayList<Student>();
        this.setClassGroupId(Long.parseLong(request.getParameter("classGroupId")));
        ClassGroup existing = classGroupDelegate.findByClassGroupId(this.getClassGroupId());
        this.module = existing.getModule();
        this.setTitle(existing.getTitle());
        this.setModule(existing.getModule());

        for (ClassRegistration registration : existing.getClassMembers()) {
            getSelectedStudents().add(registration.getStudent());
        }
        return SUCCESS;
    }

    public String updateModule() throws Exception {
        System.out.println("invoke update module action");
        //moduleDelegate.crateModule(moduleDTO);
        return SUCCESS;
    }

    public String deleteModule() throws Exception {
        System.out.println("invoke update module action");
        // moduleDelegate.crateModule(moduleDTO);
        return SUCCESS;
    }

    /**
     * @return the classGroupId
     */
    public long getClassGroupId() {
        return classGroupId;
    }

    /**
     * @param classGroupId the classGroupId to set
     */
    public void setClassGroupId(long classGroupId) {
        this.classGroupId = classGroupId;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the module
     */
    public Module getModule() {
        return module;
    }

    /**
     * @param module the module to set
     */
    public void setModule(Module module) {
        this.module = module;
    }

    /**
     * @return the modules
     */
    public List<Module> getModules() {
        return modules;
    }

    /**
     * @param modules the modules to set
     */
    public void setModules(List<Module> modules) {
        this.modules = modules;
    }

    /**
     * @return the selectedStudents
     */
    public List<Student> getSelectedStudents() {
        return selectedStudents;
    }

    /**
     * @param selectedStudents the selectedStudents to set
     */
    public void setSelectedStudents(List<Student> selectedStudents) {
        this.selectedStudents = selectedStudents;
    }

    /**
     * @return the students
     */
    public List<Student> getStudents() {
        return students;
    }

    /**
     * @param students the students to set
     */
    public void setStudents(List<Student> students) {
        this.students = students;
    }
}
